/**
 * announcement controller
 */
var Ancmt = require('../models/ancmt.js');

exports.addAncmt = function(req, res){
    if(!req.body.title  || !req.body.content){
        res.json({code: 0, msg: '缺少必要数据！'});
    } else {
        Ancmt.addAncmt(req.body.title, req.body.content, function(err){
            if(err){
                res.json({code: 0, msg: '数据库插入错误！'});
            } else {
                res.json({code: 1, msg: '发布成功！'});
            }
        });
    }
};

exports.findOne = function(req, res){
    Ancmt.findOne(function(ancmt){
        res.json({code: 1, ancmt: ancmt});
    });
}

exports.findAll = function(req, res){
    Ancmt.findAll(function (e, ancmts) {
        if(e){
            res.json({code: 0, msg: '数据库查询错误！'})
        } else {
            res.json({code: 1, ancmts: ancmts});
        }
    })
};

exports.deleteOne = function (req, res) {
    if(!req.body.id){
        res.json({code: 0, msg: '缺少必要数据！'});
    } else {
        Ancmt.deleteOne(req.body.id, function (e) {
            if(e){
                res.json({code: 0, msg: '数据库删除错误！'});
            } else {
                res.json({code: 1, msg: '删除成功！'});
            }
        })
    }
};